package com.xhkj.es;

import java.util.List;

import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hikvision.artemis.sdk.kafka.entity.parse.result.FaceLibData;
import com.xhkj.componet.MyESClient;
import com.xhkj.componet.SaticScheduleTask;
import com.xhkj.model.Camera;
import com.xhkj.model.EsFace;

public class UploadFaceData2ES {
	private static ObjectMapper mapper = new ObjectMapper();
    public static void insert(List<FaceLibData> faceLibRecogList) throws Exception {
    	for(FaceLibData ls:faceLibRecogList) {
    		EsFace ev = new EsFace();
    		ev.setCameraIndexCode(ls.getCameraIndexCode());
    		ev.setCaptureTime(ls.getCaptureTime());
    		ev.setCertificateNumber(ls.getCertificateNumber());
    		ev.setId(ls.getTraceUuid());
    		ev.setTargetPicUrl(ls.getFacePicUrl());
    		Camera camera = SaticScheduleTask.faceCameraMap.get(ls.getCameraIndexCode());
    		if(camera != null) {
//    			System.out.println("face camera find " + ls.getCameraIndexCode());
    			ev.setLatitude(camera.getLatitude());
    			ev.setLongitude(camera.getLongitude());
    			ev.setCameraName(camera.getName());
    		}
    		
    		String json = mapper.writeValueAsString(ev);
    		RestHighLevelClient client = MyESClient.getClient();
    		IndexRequest indexRequest = new IndexRequest("std_hkws_face");
    		indexRequest.source(json, XContentType.JSON);
    		client.index(indexRequest, RequestOptions.DEFAULT);
    	}
    }
}
